package stc.skymobi.netty.handler.codec.memcached;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * {@link AbstractTransCoder} is nearly the same as the interface
 * {@link TransCoder}, the only difference is that you needn't return the
 * written size for memcached set operation.
 *
 * @author Xingen Wang
 * @since 2.5.0
 * @see TransCoder
 * @see ObjectTransCoder
 */
public abstract class AbstractTransCoder implements TransCoder {

	/*
	 * (non-Javadoc)
	 *
	 * @seecom.schooner.MemCached.TransCoder#encode(com.schooner.MemCached.
	 * SockOutputStream, java.lang.Object)
	 */
	public int encode(ByteArrayOutputStream out, Object object) throws IOException {
		out.reset();
		encode((OutputStream) out, object);
		return out.size();
	}

	/**
	 * encode the java object into outputstream.
	 *
	 * @param out
	 *            outputstream to hold the data.
	 * @param object
	 *            object to be encoded.
	 * @throws java.io.IOException
	 */
	public abstract void encode(OutputStream out, Object object) throws IOException;

}
